package com.demo.study.config;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryManagerMXBean;
import java.lang.management.RuntimeMXBean;
import java.util.List;

/**
 * @ClassName: JVMTest
 * @Author : sz
 * @Date :2024/11/14  21:32
 * @Version :1.0
 */
public class JVMTest {

    public static void main(String[] args) {


        RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
        MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
        // 获取JVM启动参数
        List<String> inputArguments = runtimeMxBean.getInputArguments();
        System.out.println("JVM Default Parameters:");
        for (String arg : inputArguments) {
            System.out.println(arg);
        }
        long init = memoryMXBean.getHeapMemoryUsage().getInit();
        long max = memoryMXBean.getHeapMemoryUsage().getMax();
        long used = memoryMXBean.getHeapMemoryUsage().getUsed();
        System.out.println("init:"+init/(1024*1024)+" MB"+" max:"+max/(1024*1024)+" MB"+" used:"+used);
        // 获取系统属性
        System.out.println("\nSystem Properties:");
        System.getProperties().list(System.out);
    }
}

